home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / adjct.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  226 lines

  1. ; $Id: adjct.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO    ADJCT        ;ADJUST COLOR TABLES WITH JOYSTICK
  7. ;+
  8. ; NAME:
  9. ;    ADJCT
  10. ;
  11. ; PURPOSE:
  12. ;    Interactively adjust color tables using mouse input.
  13. ;
  14. ; CATEGORY:
  15. ;    Image display.
  16. ;
  17. ; CALLING SEQUENCE:
  18. ;    ADJCT
  19. ;
  20. ; INPUTS:
  21. ;    No explicit inputs.
  22. ;
  23. ; OUTPUTS:
  24. ;    No explicit outputs.
  25. ;
  26. ; COMMON BLOCKS:
  27. ;    COLORS:  The color table common block.
  28. ;
  29. ; SIDE EFFECTS:
  30. ;    Color tables are modified.
  31. ;
  32. ; RESTRICTIONS:
  33. ;    None.
  34. ;
  35. ; PROCEDURE:
  36. ;    A new window is created and a graph of the color output value
  37. ;    versus pixel value is created.  The user can adjust this function
  38. ;    a number of ways using the mouse.
  39. ;
  40. ; MODIFICATION HISTORY:
  41. ;    DMS, March, 1988, written.
  42. ;    DMS, April, 1989, modified cursor handling to use less CPU.
  43. ;-
  44.  
  45. common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  46.  
  47. on_error,2              ;Return to caller if an error occurs
  48. nc = !d.table_size    ;# of colors avail
  49. if nc eq 0 then message, 'Device has static color tables, can''t adjust'
  50.  
  51. old_noclip = !p.noclip
  52. !p.noclip=1        ;No clipping
  53. nc1 = nc -1
  54. old_window = !d.window    ;Previous window
  55.  
  56. if n_elements(r_orig) le 0 then begin
  57.     r_orig = bytscl(indgen(nc))
  58.     g_orig = r_orig & b_orig = r_orig
  59.     r_curr = r_orig & g_curr = r_orig & b_curr = r_orig
  60.     endif
  61. p = findgen(nc)
  62. xx = p
  63.  
  64. big = 1.0e6        ;Large slope
  65. xsize = 400        ;Window width
  66. ysize = 300
  67.  
  68. window,xs=xsize, ys=ysize, title='Intensity transformation',/free
  69. tvcrs,.5,.5,/norm
  70. tvlct,r_orig, g_orig, b_orig
  71.  
  72.  
  73. slope = 1.0
  74. inter = 0.0
  75.  
  76. choices = ['Ramp','Segments','Draw', 'Help']
  77. instr = [ 'Left = 1st endpoint, Middle = other endpoint, Rt = Done',$
  78.     'Left button for 1st pnt, Middle = following, Rt = Done', $
  79.     'Left button down to draw, up to load colors, Rt = Done', $
  80.     ' ']
  81.  
  82.  
  83.  
  84.  
  85.  
  86. plot,p,xtit='Pixel Value',ytit='Intensity'
  87. i  = menus(0, choices, instr) ;Output orig choices
  88. ramp = bytscl(indgen(1,ysize-1))
  89. for x=xsize-10,xsize-1 do tv,ramp,x,0
  90.  
  91. while 1 do begin    ;Main loop
  92.  
  93. mode = menus(1,choices,instr)    ;Get choice
  94. !err = 0        ;Reset erre
  95.  
  96. case mode of
  97. 0: begin
  98.     isub = 0
  99.     x = [0,nc-1]
  100.     y = x
  101.     oldx = x & oldy = y
  102.     mask = 0
  103.     tvrdc,x1,y1    ;data coords, wait
  104.     while !err ne 4 do begin
  105.       if !err ne 0 then begin
  106.           if !err eq 1 then isub = 0
  107.           if !err eq 2 then isub = 1
  108.           x(isub) = x1 & y(isub) = y1
  109.  
  110.       if total(abs(oldx-x)+abs(oldy-y)) ne 0 then begin
  111.           oldx = x & oldy = y
  112.           x(isub) = x1 & y(isub) = y1
  113.           dx = x(1) - x(0)
  114.           dy = float(y(1) - y(0))
  115.           if dx ne 0 then slope = dy/dx else slope = big
  116.           inter = y(1) - slope * x(1)
  117.           plots,xx,p,col=0
  118.           p = long(findgen(nc) * slope + inter) > 0 < nc1
  119.     ;        Prevent invisible color tables...
  120.           if (abs(p(0) - p(nc-1)) le nc1/4) then $
  121.             p(nc-1) = nc1 * (p(0) le nc/2)
  122.         plots,xx,p,col=nc1
  123.         r_curr = r_orig(p)
  124.         g_curr = g_orig(p)
  125.         b_curr = b_orig(p)
  126.         tvlct,r_curr,g_curr,b_curr
  127.         endif
  128.       endif
  129.       tvrdc,x1,y1,2        ;Next point
  130.     endwhile
  131.    end
  132.  
  133. 1: begin        ;Segments
  134.     p0 = 0
  135.     x = [0.,0.] & y=x
  136.     n = 0
  137.     while (!err ne 4) do begin
  138.       tvrdc,x1,y1,1
  139.       if !err eq 1 then n = 0
  140.       if (!err and 3) ne 0 then begin
  141.         x1 = x1 < (nc-1) > 0 & y1 = y1 < nc1 > 0
  142.         x(p0) = x1 & y(p0) = y1
  143.           dx = x(p0) - x(1-p0)
  144.         dy = y(p0) - y(1-p0)
  145.         n = n + 1
  146.         if (n ge 2) and (dx ne 0) then begin
  147.             slope = dy/dx
  148.             inter = y(p0) - slope * x(p0)
  149.             x0 = x(1-p0) < x(p0)
  150.             pp = (findgen(abs(dx)+1)+x0) *slope +inter
  151.             plots,xx,p,col=0
  152.             p(x0) = pp
  153.     ; Prevent invisibility
  154.             if (abs(p(0) - p(nc-1)) le nc1/4) then $
  155.               p(nc-1) = nc1 * (p(0) le nc/2)
  156.             plots,xx,p,col=nc1
  157.             r_curr = r_orig(p)
  158.             g_curr = g_orig(p)
  159.             b_curr = b_orig(p)
  160.             tvlct,r_curr,g_curr,b_curr
  161.             endif
  162.       p0 = 1-p0        ;Swap endpoints
  163.       endif
  164.     endwhile
  165.     endcase        
  166.  
  167. 2:    while !err ne 4 do begin
  168.         tvrdc,x0,y0,1    ;Get 1st point
  169.         x0 = x0 < (nc-1) > 0 & y0 = y0 < nc1 > 0
  170.         while !err eq 1 do begin
  171.          tvrdc,x1,y1,0    ;Next pnt
  172.          x1 = x1 < (nc-1) > 0 & y1 = y1 < nc1 > 0
  173.          if x1 ne x0 then begin    ;Draw
  174.             i0 = fix(x0 < x1)
  175.             i1 = fix((x1 > x0) + 0.9999)
  176.             i00 = i0 - 1 > 0
  177.             i11 = i1 + 1 < nc1
  178.             xxx = xx(i00:i11)
  179.             plots,xxx,p(i00:i11),col=0 ;Erase old segment
  180.             slope = (y1 - y0) / (x1 - x0)
  181.             inter = y1 - slope * x1
  182.             p(i0) = xx(i0:i1) * slope + inter
  183.             plots,xxx,p(i00:i11),col=nc1
  184.             x0 = x1
  185.             y0 = y1
  186.             endif    ;Draw
  187.           endwhile
  188.             ; Prevent invisibility
  189.             if (abs(p(0) - p(nc-1)) le nc1/4) then $
  190.           p(nc-1) = nc1 * (p(0) le nc/2)
  191.         r_curr = r_orig(p)
  192.         g_curr = g_orig(p)
  193.         b_curr = b_orig(p)
  194.         tvlct,r_curr,g_curr,b_curr
  195.     endwhile
  196.  
  197. 3:    begin
  198.     print,'All functions: right button ends function.'
  199.     print,'       Clicking right button twice exits procedure.'
  200.     print,'Ramp - Left button controls one endpoint of ramp (normally the left).'
  201.     print,'       Middle controls other endpoint.  Hint: Move the cursor along'
  202.     print,'        an axis border with either button depressed.'
  203.     print,'Segments - Left button begins a new segment.'
  204.     print,'       Middle button marks a vertex and continues a segment.'
  205.     print,'Draw - Depressing the left button and moving it marks a series of points.'
  206.     print,'       Releasing it updates the color tables with the curve.'
  207.     endcase
  208.  
  209. -1:    begin        ;Quit entry
  210.     wdelete        ;Done with window
  211.     if old_window ge 0 then begin
  212.         wset,old_window    ;Restore old window
  213.         tvcrs,!d.x_vsize/2, !d.y_vsize/2,/dev ;Put cursor in middle
  214. ;;;        tvcrs,0        ;and hide it
  215.         endif
  216.     !p.noclip = old_noclip
  217.     return
  218.     end
  219. else:    begin
  220.     end
  221. endcase
  222.     ;Clean up instructions
  223. endwhile
  224.  
  225. end
  226.